import 'package:flutter/cupertino.dart';

mixin HiAppLifeCycle<T extends StatefulWidget>
    on State<T>, WidgetsBindingObserver {
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  /*
  resume 可见，能响应操作
  inactive 处于不可活动状态，无法处理用户响应
  paused 不可见，不能响应用户输入，但在后台继续活动中
   */
  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    // TODO: implement didChangeAppLifecycleState
    onChangeAppLifecycleState(state);
  }

  @override
  void didHaveMemoryPressure() {
    // TODO: implement didHaveMemoryPressure
    onHaveMemoryPressure();
  }

  onChangeAppLifecycleState(AppLifecycleState state);

  onHaveMemoryPressure();

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }
}
